<script>
	import setDot from '@/pages/utils/setdot.js';
	export default {
		onLaunch: function() {
			console.log('项目运行啦~~', uni.getStorageSync('firstOpen'));
			if (!uni.getStorageSync('firstOpen')) {
				console.log('执行啦首次启动埋点');
				setDot('SYSTEM_APP_OPEN');
				uni.setStorageSync('firstOpen', true)
			} else {
				console.log('首次启动埋点执行过啦');
			}
			// #ifndef H5
			uni.setStorage({
				key: 'navigateHeight',
				data: plus.navigator.getStatusbarHeight(),
				success: () => {
					console.log('当前头部的高度', uni.getStorageSync('navigateHeight'));
					console.log(typeof(uni.getStorageSync('navigateHeight')));
				}
			})
			const adjust = uni.requireNativePlugin("sn-adjust");

			function getAdjustEnabled() {
				return new Promise((resolve) => {
					adjust.getEnabled((enable) => {
						console.log('adjust 打开了么:', enable);
						resolve(enable);
					});
				});
			}

			function getAdjustAttribution() {
				return new Promise((resolve) => {
					adjust.getAttribution((res) => {
						console.log('getAttribution ----', res);
						resolve(res);
					});
				});
			}

			function getGoogleAdId() {
				return new Promise((resolve) => {
					adjust.getGoogleAdId((gaid) => {
						console.log('拿到 gaid 了吗:', gaid);
						resolve(gaid);
					});
				});
			}

			async function initAdjust() {
				adjust.setEnabled(true);

				await getAdjustEnabled();

				const attribution = await getAdjustAttribution();
				if (attribution.code === 0 && attribution.data) {
					const data = attribution.data;
					const infoList = [
						data.trackerToken && `tt: ${data.trackerToken}`,
						data.network && `net: ${data.network}`,
						data.trackerName && `tn: ${data.trackerName}`,
						data.adid && `adid: ${data.adid}`,
						data.campaign && `cam: ${data.campaign}`,
						data.adgroup && `adg: ${data.adgroup}`,
						data.creative && `cre: ${data.creative}`,
						data.clickLabel && `cl: ${data.clickLabel}`,
						data.costType && `ct: ${data.costType}`,
						data.costAmount && `ca: ${data.costAmount}`,
						data.costCurrency && `cc: ${data.costCurrency}`,
						data.fbInstallReferrer && `fir: ${data.fbInstallReferrer}`,
					].filter(Boolean); // 移除空值

					const adjustData = infoList.join(' ');
					console.log('adjustData 有么:', adjustData);

					uni.setStorage({
						key: 'adjustData',
						data: adjustData,
						success: () => {
							console.log('存储 adjust 信息:', uni.getStorageSync('adjustData'));
						}
					});
				}

				const gaid = await getGoogleAdId();
				uni.setStorageSync('gaid', gaid);
			}

			initAdjust();

			// #endif
			//语言
			const systemInfo = uni.getSystemInfoSync();
			const systemLang = systemInfo.language;
			console.log('系统语言名字', systemLang);
			if (!uni.getStorageSync("isShowlangPopUp")) { //用户没点击过
				if (systemLang === 'es' || systemLang == 'th-TH') {
					console.log('跟随系统语言');
				} else {
					if (!uni.getStorageSync("ckecksystemlang")) {
						// 系统语言不是 es/th，且未设置过语言，强制为泰语
						this.$i18n.locale = 'th';
						uni.setLocale('th');
						uni.setStorageSync('ckecksystemlang', true);
						console.log('默认设为泰语');
					}
				}
			}
			console.log('app设置的语言', uni.getLocale());
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	/*每个页面公共css */
</style>